import axios, { type AxiosResponse } from 'axios'

// import type 是 专门用于导入 类型的 命令
// import type { AxiosResponse } from 'axios'

type City = { cityId: number; isHot: 0 | 1; name: string; pinyin: string }

type ApiCityList = {
  data: {
    cities: City[]
  }
  msg: string
  status: number
}

/**
 * 响应拦截器
 */
axios.interceptors.response.use(
  (response) => {
    // 将 response.data 取出来再返回
    return response.data.data
  },
  (error) => {
    return Promise.reject(error)
  }
)

/**
 * get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
 */
axios
  .get<ApiCityList, ApiCityList['data']>('https://m.maizuo.com/gateway?k=1282506', {
    headers: {
      'X-Host': 'mall.film-ticket.city.list'
    }
  })
  .then((response) => {
    console.log('response', response)
    const currentCity = response.cities[0]

    console.log('currentCity', currentCity)
  })
